package com.sina.weibo.sdk.network.intercept;

import android.os.Bundle;
import android.text.TextUtils;
import com.sina.weibo.sdk.auth.Oauth2AccessToken;
import com.sina.weibo.sdk.net.HttpManager;
import com.sina.weibo.sdk.network.IRequestIntercept;
import com.sina.weibo.sdk.network.IRequestParam;
import com.sina.weibo.sdk.network.IRequestParam.RequestType;
import com.sina.weibo.sdk.network.exception.InterceptException;
import o.fnj;
import o.fnm;

public class CommonParamInterception implements IRequestIntercept {
    public static String aidInfo;
    private static String appKey;

    public boolean needIntercept(IRequestParam iRequestParam, Bundle bundle) {
        return true;
    }

    public static void setAppKey(String str) {
        appKey = str;
    }

    public boolean doIntercept(IRequestParam iRequestParam, Bundle bundle) throws InterceptException {
        if (TextUtils.isEmpty(aidInfo)) {
            aidInfo = fnj.ॱ().ˏ(iRequestParam.getContext(), appKey);
        }
        if (TextUtils.isEmpty(aidInfo)) {
            throw new InterceptException("aid get error");
        }
        Bundle getBundle;
        if (!TextUtils.isEmpty(aidInfo)) {
            bundle.putString("aid", aidInfo);
        }
        if (iRequestParam.getMethod() == RequestType.GET) {
            getBundle = iRequestParam.getGetBundle();
        } else {
            getBundle = iRequestParam.getPostBundle();
        }
        String str = "";
        Object obj = getBundle.get("access_token");
        Object obj2 = getBundle.get(Oauth2AccessToken.KEY_REFRESH_TOKEN);
        Object obj3 = getBundle.get("phone");
        String str2 = (obj == null || !(obj instanceof String)) ? (obj2 == null || !(obj2 instanceof String)) ? (obj3 == null || !(obj3 instanceof String)) ? str : (String) obj3 : (String) obj2 : (String) obj;
        String timestamp = getTimestamp();
        bundle.putString("oauth_timestamp", timestamp);
        bundle.putString("oauth_sign", HttpManager.getOauthSign(iRequestParam.getContext(), aidInfo, str2, appKey, timestamp));
        fnm.ˎ("weiboSdk param", aidInfo + "  " + timestamp + "  " + appKey + "   " + str2);
        return false;
    }

    private static String getTimestamp() {
        return String.valueOf(System.currentTimeMillis() / 1000);
    }
}
